import { _decorator, Color, Component, Label, Node, Sprite } from 'cc';
import { Hero, NumberStrList } from '../entity/Hero';
import { UIManager } from '../common/UIManager';
import { PrefabEnum } from '../common/PrefabEnum';
import { HeroDetail } from './HeroDetail';
const { ccclass, property } = _decorator;

@ccclass('HeroItem')
export class HeroItem extends Component {
    
    @property(Sprite)
    cover:Sprite
    @property(Label)
    level:Label
    @property(Label)
    heroName:Label

    private hero:Hero
    
    start() {

        this.node.on(Node.EventType.TOUCH_END, this.toDetail, this)
    }

    async setData(hero:Hero){
        this.hero = hero
        this.cover.spriteFrame = await hero.getHeadImg()
        this.heroName.string = hero.name
        this.level.string = `${NumberStrList[hero.ad]}阶·${hero.en}星·${hero.l}级`

        if(hero.ad == 0){
            this.level.string = '未激活'
            this.cover.color = new Color('#777777')
        }

        
    }

    async toDetail(){
        let ui = await UIManager.instance.openUI(PrefabEnum.HeroDetail)
        ui.getComponent(HeroDetail).setData(this.hero)
    }
    
}


